﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Singleton<T> : MonoBehaviour where T : Singleton<T>
{
    private static T _singleton;
    public static T Instance
    {
        get
        {
            if (_singleton == null)
            {
                var instanceObj = new GameObject(typeof(T).ToString());
                DontDestroyOnLoad(instanceObj);
                _singleton = instanceObj.AddComponent<T>();
            }

            return _singleton;
        }

        private set{}
    }
}
